/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import model.Course;
import org.xml.sax.SAXException;

/**
 *
 * @author Tina
 */
public class Coursemanagement {
    	Course[] courses = new Course[9999];
	
		public Coursemanagement(){	

		}
		
		//gehe Kursarray solange durch bis ende erreicht ist
		public void saveCourse(Course course) throws SAXException, IOException{
                try{
                   WriteXMLFileCourse.main(course.getCoursename(), course.getCredits(), course.getCourseDescription(), course.getCoursetype());
                   } catch (ParserConfigurationException | TransformerException ex) {
                        Logger.getLogger(Coursemanagement.class.getName()).log(Level.SEVERE, null, ex);
                        }
		}
		
		//suche array Stelle des Kurses
		public int searchCourse(String coursename){
			for (int i = 0; i < courses.length; i++) {
				if(courses[i] == null) break;
				if(courses[i].getCoursename().equals(coursename)){
					return i;
				}
			}
			return 9999; //ende der for schleife
		}
		
		public void testArray(){
			for (int i = 0; i < courses.length; i++) {
				if(courses[i] == null) break;
				System.out.print(courses[i].courseDescription + "\n");
			}
		}
	
}
